Skip to content
12345678
CONSTRUCTING

Asciinema Player

Word count
475 words
Reading time
3 minutes

Installation

Install @nolebase/ui-asciinema to your project dependencies by running the following command:

shell
ni @nolebase/ui-asciinema
shell
pnpm add @nolebase/ui-asciinema
shell
npm install @nolebase/ui-asciinema
shell
yarn add @nolebase/ui-asciinema

Usage

Add the package to Vite's ssr.noExternal configuration. Without this, your site may not build. (Ref: Vite's ssr.noExternal config docs.)

ts
// vite.config.ts
export default defineConfig({
  ssr: {
    noExternal: [
      "@nolebase/ui-asciinema",
    ],
  },
})

Then import NuAsciinemaPlayer and asciinema-player's stylesheet in your Vue file. (Ref: asciinema-player's styling docs.)

vue
<script setup>
// somewhere.vue
import { NuAsciinemaPlayer } from '@nolebase/ui-asciinema'
import 'asciinema-player/dist/bundle/asciinema-player.css'
</script>

<template>
  <NuAsciinemaPlayer
    src="/asciinema/test-nyancat.cast"
    :preload="true"
    :cols="400"
    :rows="40"
    :auto-play="true"
    :controls="true"
    :terminal-font-size="'12px'"
    :loop="true"
  />
</template>

VitePress

Instead of configuring Vite's ssr.noExternal in a vite.config.ts, you can configure it in the VitePress vite config. (Ref: VitePress's Vite configuration docs.)

ts
// **/.vitepress/config.ts
export default defineConfig({
  vite: {
    ssr: {
      noExternal: [
        "@nolebase/ui-asciinema",
      ],
    },
  },
})

If the component is only used by a few pages, it's recommended to explicitly import it and the asciinema-player stylesheet where they are used. This allows them to be properly code-split and only loaded when the relevant pages are shown:

  • Markdown

    html
    <script setup>
    // somewhere.md
    import { NuAsciinemaPlayer } from '@nolebase/ui-asciinema'
    import 'asciinema-player/dist/bundle/asciinema-player.css'
    </script>
    
    <NuAsciinemaPlayer
      src="/asciinema/test-nyancat.cast"
      :preload="true"
      :cols="400"
      :rows="40"
      :auto-play="true"
      :controls="true"
      :terminal-font-size="'12px'"
      :loop="true"
    />
  • Vue

    vue
    <script setup>
    // somewhere.vue
    import { NuAsciinemaPlayer } from '@nolebase/ui-asciinema'
    import 'asciinema-player/dist/bundle/asciinema-player.css'
    </script>
    
    <template>
      <NuAsciinemaPlayer
        src="/asciinema/test-nyancat.cast"
        :preload="true"
        :cols="400"
        :rows="40"
        :auto-play="true"
        :controls="true"
        :terminal-font-size="'12px'"
        :loop="true"
      />
    </template>

If the component is going to be used on most of the pages, it and the asciinema-player stylesheet can be registered globally by customizing the VitePress Vue app instance.

ts
// **/.vitepress/theme/index.ts
import { NuAsciinemaPlayer } from "@nolebase/ui-asciinema";
import "asciinema-player/dist/bundle/asciinema-player.css";

export default {
  enhanceApp({ app, router, siteData }) {
    app.component("NuAsciinemaPlayer", NuAsciinemaPlayer);
  }
}
  • Markdown

    html
    <!-- somewhere.md -->
    
    <NuAsciinemaPlayer
      src="/asciinema/test-nyancat.cast"
      :preload="true"
      :cols="400"
      :rows="40"
      :auto-play="true"
      :controls="true"
      :terminal-font-size="'12px'"
      :loop="true"
    />
  • Vue

    vue
    <!-- somewhere.vue -->
    
    <template>
      <NuAsciinemaPlayer
        src="/asciinema/test-nyancat.cast"
        :preload="true"
        :cols="400"
        :rows="40"
        :auto-play="true"
        :controls="true"
        :terminal-font-size="'12px'"
        :loop="true"
      />
    </template>

Ref: VitePress Registering Global Components docs.

Options

Refer to asciinema.d.ts.

Acknowledgements

Contributors

The avatar of contributor named as Neko Neko
The avatar of contributor named as Henry Bley-Vroman Henry Bley-Vroman

Changelog

Layout Switch

Adjust the layout style of VitePress to adapt to different reading needs and screens.

Expand all
The sidebar and content area occupy the entire width of the screen.
Expand sidebar with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Expand all with adjustable values
Expand sidebar width and add a new slider for user to choose and customize their desired width of the maximum width of sidebar can go, but the content area width will remain the same.
Original width
The original layout width of VitePress

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.

Spotlight

Highlight the line where the mouse is currently hovering in the content to optimize for users who may have reading and focusing difficulties.

ONOn
Turn on Spotlight.
OFFOff
Turn off Spotlight.

Spotlight Styles

Adjust the styles of Spotlight.

Under
Add a solid background color underneath the hovering element to highlight where the cursor is currently hovering.
Aside
Add a fixed line with solid color aside the hovering element to highlight where the cursor is currently hovering.